#!/usr/bin/env python
from datetime import date
from datetime import timedelta
import random
import string
import sys

sys.path.append("..")

from sixpack.models import Client
from sixpack.models import Experiment
from sixpack.db import REDIS

experiments = {
    'show-bieber': ['yes', 'no'],
    'show-bieber': ['yes', 'no', 'call-me-maybe'],
    'blurry-buy-now': ['yes', 'no'],
    'button-color': ['blue', 'green', 'red', 'black', 'orange'],
    'solo-cup': ['red', 'green'],
    'jose': ['troll', 'no-troll']
}

for d in range(1, 8):

    _date = date.today() - timedelta(days=d)
    print _date
    # generate 20 client ids
    client_ids = []
    for i in range(1, 2000):
        client_ids.append(''.join(random.choice(string.ascii_lowercase + string.digits + '-_') for x in range(30)))

    client_exp = []
    participations = {}
    for x in range(1, 10):
        for experiment, alternatives in experiments.iteritems():
            _id = random.choice(client_ids)

            client = Client(_id, REDIS)
            experiment = Experiment.find_or_create(experiment, alternatives, redis=REDIS)

            chosen_alt = random.choice(experiment.alternatives)
            chosen_alt.record_participation(client, _date)

            # no dupes, plz
            client_ids.remove(_id)

            client_exp.append((_id, experiment))

    for key, tup in enumerate(client_exp):
        if key % 2:
            client_id, exp = tup
            client = Client(client_id, REDIS)
            experiment = Experiment.find(exp.name, REDIS)
            alternative = experiment.existing_alternative(client)
            alternative.record_conversion(client, _date)
            #alternative = experiment.convert(client, _date)

print 'done'